{include file="public/header"}

{load href="/public/static/Content/ThemesBusiness/ListPage.css"}

<style>
    .datagrid-view1 .datagrid-body{
        overflow: hidden !important;
    }
</style>
<!--  -->
<script src="/public/static/Scripts/common-binder-treelist-view.js"></script>
<script type="text/javascript">

    var data =null;

    var gridListHandler = new listGridHandler(data, "gridListHandler", 'gridList');
    gridListHandler.formName = '菜单列表';
    gridListHandler.enableFilter = false;
    $(function() {
        gridListHandler.bindFilter($('#gridList'));
    });
    function ShowNew() {
        var id = undefined;
        window.showBusinessForm("新建菜单", '/admin/menu/edit.html?id=' + id );
    }


    function del(){
            var id = undefined;
            var selectedRow = $('#gridList').datagrid('getSelected');
            if (!selectedRow || selectedRow.length <= 0) {
                $.messager.alert('提示', "请选择一行需要编辑的记录！", 'info');
                return -1;
            }
            id = selectedRow.id;
            if (id <=1)  {
                $.messager.alert('提示', "根菜单不可删除！", 'info');
                return;
            }
          // alert(id);


            $.messager.confirm('删除确认', '确实要删除选中的记录？', function (r) {
                if (r) {
                    $.ajax({
                        type: "POST",
                        url: '/admin/menu/del.html?id=' + id,
                    })
                    .success(function (result) {
                        if (result.status > 0) {
                            $.messager.alert('提示', result.msg, "info");
                            window.location.reload();
                        }else {
                            $.messager.alert('提示', result.msg, "error");
                        }
                    })
                    .error(function (result) {
                        var message = "很抱歉，操作出现异常！请联系管理员。";
                        if (result) {
                            if (result.responseJSON && result.responseJSON.ExceptionMessage) {
                                message = result.responseJSON.ExceptionMessage;
                            }
                            else if (result.responseText) {
                                message = result.responseText;
                            }
                        }

                        $.messager.alert('错误', message.replace("-10", ""), 'error');
                    });
                }
            });
           
    }

    function EditRecord() {

        var id = undefined;
        var selectedRow = $('#gridList').datagrid('getSelected');
        if (!selectedRow || selectedRow.length <= 0) {
            $.messager.alert('提示', "请选择一行需要编辑的记录！", 'info');
            return -1;
        }
        id = selectedRow.id;
        if (id > 1) {
            window.showBusinessForm("菜单编辑", '/admin/menu/edit.html?id=' + id);
        } else {
            $.messager.alert('提示', "根菜单不可编辑！", 'info');
        }
    }

</script>

<div class="easyui-layout" data-options="fit:true">
    <div data-options="region:'north',border:false" class="grid-toolbar-panel" id="gridList_ToolBar">
      
    {eq name="power.add" value="true"}
    <a href="#" onclick="ShowNew()" class="easyui-linkbutton grid-toolbar-button" data-options="iconCls:'icon-add'">新建菜单</a>
    {/eq}
    {eq name="power.edit" value="true"}
    <a href="#" onclick=" EditRecord() " class="easyui-linkbutton grid-toolbar-button" data-options="iconCls:'icon-edit'" title="编辑">编辑</a>
    {/eq}
    {eq name="power.del" value="true"}
    <a href="#" onclick="del()" class="easyui-linkbutton grid-toolbar-button" data-options="iconCls:'icon-remove'">删除</a>
    {/eq}

    </div>
    
    <div data-options="region:'center',border:false">
        <table id="gridList" 
               data-options="url: '/admin/menu/index.html?ajax=1',rownumbers: true ,idField: 'id' ,treeField: 'text'">
            <thead>
                <tr>
                    <th data-options="field:'text'" width="45%">菜单名称</th>
                    <th data-options="field:'url'" width="20%">链接地址</th>
                    <th data-options="field:'CreateDate'" width="20%">创建时间</th>
                    <th data-options="field:'isCatalog'" width="10%">启用状态</th>
                </tr>
            </thead>
        </table>
    </div>
</div>
{include file="public/footer"/}